﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace MyMovieInfo.LSPViolationExample
{
    class RectangleSquare
    {
        public static void MMain(string[] args)
        {
            Rectangle rectangle = new Rectangle();
            rectangle.Height = 4;
            rectangle.Width = 5;
            AssertTheArea(rectangle);

            Rectangle square = new Square();
            rectangle.Height = 4;
            square.Height = 5;
            AssertTheArea(square);

            //You clearly have the wrong abstraction to represent 
            //   both a square and a rectangle for this scenario. 
            //This is evidenced by the square overriding the height and width 
            //    properties of the rectangle, and changing the expected behavior of a rectangle.
        }

        private static void AssertTheArea(Square square)
        {
            int expectedArea = 20;
            int actualArea = square.Area();
            Debug.Assert(expectedArea == actualArea);
        }


        private static void AssertTheArea(Rectangle rectangle)
        {
            int expectedArea = 20;
            int actualArea = rectangle.Area();
            Debug.Assert(expectedArea == actualArea);
        }
    }


    class Rectangle
    {
        public virtual int Height { get; set; }
        public virtual int Width { get; set; }

        public int Area()
        {
            return Height * Width;
        }
    }

    
    class Square : Rectangle
    {
        public override int Height
        {
            get { return base.Height; }
            set
            {
                base.Height = value;
                base.Width = value;
            }
        }

        public override int Width
        {
            get { return base.Width; }
            set
            {
                base.Width = value;
                base.Height = value;
            }
        }
    }
}
